package com.appspot.moviesessions;

import android.view.View;
import android.view.View.OnClickListener;

public class MovieInfoPresenter {

	private MovieInfoView view;
	private LoaderFactory loaderFactory;
	private IntentFactory intentFactory;
	private ContentUri contentUri;

	public MovieInfoPresenter(MovieInfoView movieInfoView,
			LoaderFactory loaderFactory, IntentFactory intentFactory,
			ContentUri contentUri) {
		this.view = movieInfoView;
		this.loaderFactory = loaderFactory;
		this.intentFactory = intentFactory;
		this.contentUri = contentUri;
	}

	public void onStart() {
		String dataString = view.getIntent().getDataString();
		final long movieId = contentUri.parseId(dataString);
		Loader loader = loaderFactory.movieInfoLoader(dataString);
		view.getSupportLoaderManager().initLoader(0x02, null, loader);
		view.getMovieInfo().setAdapter(loader);
		view.getSessionsButton().setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				view.startActivity(intentFactory.launchMovieSessionIntent(
						view.getContext(), movieId));
			}
		});

	}

	public void onDestroy() {

	}

}
